package com.byxy.ssm.demo.dao;



import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.byxy.ssm.demo.entity.User;

public interface UserDao {
	//声明id  usermap   下面可以共用
	@Results(id = "usermap",value ={
		@Result(column="user_id",property="userId",id=true),
		@Result(column="user_name",property="userName"),
		@Result(column="user_nick",property="userNick"),
		@Result(column="user_password",property="userPassword"),
		@Result(column="user_status",property="userStatus"),
		@Result(column="user_type",property="userType")
	})
@Select("select * from user where user_id=#{userId}")
	User getById(Integer userId);
	
//	@ResultMap("usermap")
//	@Select("select * from user where user_name=#{userName} and user_password=#{userPassword}")
//	//参数多余一个，必须写@param注解
//	User getByNameAndPassword(@Param("userName")String userName, @Param("userPassword")String userPassword);
	
	@Insert("insert into user(user_name,user_nick,user_password,user_type) values(#{user.userName},#{user.userNick},#{user.userPassword},#{user.userType})")
	public void add(@Param("user")User user);
	
	@ResultMap("usermap")
	@Select("select * from user where user_name=#{username} and user_password=#{password}")
	public User login(@Param("username")String username,@Param("password")String password);
	
	@ResultMap("usermap")
	@Select("select * from user where user_name=#{username}")
	public User getByUsername(@Param("username")String username);
	
	@ResultMap("usermap")
	@Select("select * from user ")
	public List<User> findAll();
}
